package com.jy.listener;

import com.alibaba.fastjson2.JSON;
import com.jy.pojo.Car;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class MessageListener {
    @Autowired
    RedisTemplate redisTemplate;

    @RabbitListener(queuesToDeclare = @Queue("car.upadd"))
    public void upadd(String message){
        Car car= JSON.parseObject(message,Car.class);
        redisTemplate.boundHashOps("carHash").put(car.getId()+"",message);
    }

    @RabbitListener(queuesToDeclare = @Queue("car.delete"))
    public void delete(Integer id){
        redisTemplate.boundHashOps("carHash").delete(id+"");
    }
}
